#!/usr/bin/env bash

# ijview: a script for displaying an image file in ImageJ
#         using the Bio-Formats Importer plugin

# Required JARs: loci_tools.jar or bioformats_package.jar, ij.jar

BF_DIR=`dirname "$0"`

source "$BF_DIR/config.sh"

if [ -z "$BF_DEVEL" ]
then
  # Developer environment variable unset; add JAR libraries to classpath.
  if [ -e "$BF_JAR_DIR/ij.jar" ]
  then
    BF_CP="$BF_JAR_DIR/ij.jar"
  else
    # Libraries not found; issue an error
    echo "Required JAR libraries not found. Please download:"
    echo "  ij.jar"
    echo "from:"
    echo "  http://imagej.nih.gov/ij/upgrade/"
    echo "and place in the same directory as the command line tools."
    echo ""
    exit 3
  fi
  if [ -e "$BF_JAR_DIR/bio-formats_plugins.jar" ]
  then
    BF_CP="$BF_CP:$BF_JAR_DIR/bio-formats_plugins.jar"
  elif [ ! -e "$BF_JAR_DIR/loci_tools.jar" -a ! -e "$BF_JAR_DIR/bioformats_package.jar" ]
  then
    # Libraries not found; issue an error
    echo "Required JAR libraries not found. Please download:"
    echo "  bioformats_package.jar"
    echo "from:"
    echo "  http://www.openmicroscopy.org/site/products/bio-formats/downloads"
    echo "and place in the same directory as the command line tools."
    echo ""
    exit 4
  fi
fi

BF_PROG=loci.plugins.in.Importer \
  BF_CP="$BF_CP" "$BF_DIR/bf.sh" "$@"
